package com.LA_houseLease.app.service.impl;

import com.LA_houseLease.app.service.SmsService;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SmsServiceImpl implements SmsService {

    @Autowired
    private Client client;
    /**
     * 发送短信验证码
     * @param phone
     * @param code
     */
    @Override
    public void sendSMS(String phone, String code) {
        SendSmsRequest request = new SendSmsRequest();
        request.setPhoneNumbers(phone); //设置接收的手机号
        request.setSignName("阿里云短信测试"); //设置签名名称
        request.setTemplateCode("SMS_154950909"); //设置模板编码
        request.setTemplateParam("{\"code\":\""+ code + "\"}"); //传入模板参数
        try {
            client.sendSms(request);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}














